package com.juyu.miliao.scheduler.dao.mysql;

import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import com.juyu.miliao.scheduler.domin.UserWallet;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
public class UserWalletDao {
	@Autowired
	private SqlSession sqlSession;
	
	@Operate("strategy('byUserId', #id)")
	public UserWallet getUserWalletById(long id){
		return sqlSession.selectOne("getUserWalletById", id);
	}

	@Operate("strategy('byUserId', #entity.userId)")
	public int reviseDiamond(UserWallet entity){
		return sqlSession.update("reviseDiamond", entity);
	}

	@Operate("strategy('byUserId', #entity.userId)")
	public int minusDiamond(UserWallet entity){
		return sqlSession.update("minusDiamond", entity);
	}

	@Operate("strategy('byUserId', #entity.userId)")
	public int reviseDeposit(UserWallet entity){
		return sqlSession.update("reviseDeposit", entity);
	}

	@Operate("strategy('byUserId', #entity.userId)")
	public int minusDeposit(UserWallet entity){
		return sqlSession.update("minusDeposit", entity);
	}

	@Operate("strategy('byUserId', #entity.userId)")
	public int plusUserWalletBeans(UserWallet entity) {

		return sqlSession.update("plusUserWalletBeans",entity);
	}
	@Operate("strategy('byUserId', #userId)")
    public int addUserSendBeans(Long userId, Long beans) {
		Map<String, Object> map = new HashMap<>(4);
		map.put("userId", userId);
		map.put("beans", beans);
		return sqlSession.update("addUserWalletBeans",map);
    }
}
